<?php
/**
 * NOTICE OF LICENSE
 *
 * This source file is subject to the  Academic Free License (AFL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to support@zprofess.com so we can send you a copy immediately.
 *
 * @category   	Prestashop module
 * @package		Review & Rating Synthesis
 * @version 	1.0.2
 * @author 		Rukan <rukanhitokiri@zprofess.com>
 * @copyright   Copyright (c) 2012 ZPROFESS. (http://www.zprofess.com)
 * @license    	http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */

class ZCustomerBadges extends ObjectModel
{
	public		$name;
	public 		$id_zcustomer;
	
	protected	$table = 'zcustomer_badges';
	protected	$identifier = 'id_zcustomer_badges';
	
	protected	$fieldsRequiredLang = array('name');
	protected	$fieldsSizeLang = array('name' => 128);
	protected	$fieldsValidateLang = array('name' => 'isGenericName');
	
	/**
	 * Prepare fields for ObjectModel class (add, update)
	 * All fields are verified (pSQL, intval...)
	 * @view ObjectModel::getFields()
	 *
	 * @return array All object fields
	 */
	public function getFields()
	{
		parent::validateFields();
		$fields['id_zcustomer'] = pSQL($this->id_zcustomer);
		return $fields;
	}
	
	/**
	 * Check then return multilingual fields for database interaction
	 *
	 * @return array Multilingual fields
	 */
	public function getTranslationsFieldsChild()
	{
		parent::validateFieldsLang();
		return parent::getTranslationsFields(array('name'));
	}
	
	/*********************
	 * BackOffice & Grid *
	 *********************/
	
	/***************
	 * FrontOffice *
	 ***************/
	
 	public static function getCustomerByBadges($id_lang)
 	{
        $sql = '
		SELECT zb.`id_zcustomer`, zbl.`name`
        	FROM `'._DB_PREFIX_.'zcustomer_badges` zb
            LEFT JOIN `'._DB_PREFIX_.'zcustomer_badges_lang` zbl 
                ON (zb.`id_zcustomer_badges` = zbl.`id_zcustomer_badges`)
            WHERE zbl.`id_lang` = '.(int)($id_lang);
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
            return $result;
    }
	/*********************
	 * BackOffice & Form *
	 *********************/
}